<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    x:Class="OpenLS.UI.Themes.MenuItemResources"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:oui="clr-namespace:OpenLS.UI"
  xmlns:ouit="clr-namespace:OpenLS.UI.Themes"
  xmlns:Internals="clr-namespace:OpenLS.UI.Internals"
    >
    <ResourceDictionary.MergedDictionaries>
        <ouit:ContentPresenterResources/>
    </ResourceDictionary.MergedDictionaries>
    <Style TargetType="{x:Type Rectangle}" x:Key="DebugRect">
        <Setter Property="Width" Value="10"/>
        <Setter Property="Height" Value="5"/>
        <Setter Property="Fill" Value="Gray"/>
        <Setter Property="Visibility" Value="Collapsed"/>
    </Style>
    <Style TargetType="{x:Type Border}" x:Key="roundMenuItemBorder">
        <Setter Property="CornerRadius" Value="2"/>
    </Style>



    <Geometry x:Key="downArrowGeometry">M 0 0 L 2.5 3 L 5 0 Z</Geometry>
    <Geometry x:Key="rightArrowGeometry">M 0 0 L 3 2.5 L 0 5 Z</Geometry>
    <Style TargetType="{x:Type Border}" x:Key="roundBorder">
        <Setter Property="CornerRadius" Value="2"/>
    </Style>

    <ControlTemplate x:Key="TopLevelItemTemplateKey" TargetType="{x:Type MenuItem}">
        <Border
      x:Name="ClassicBorder" Style="{StaticResource roundBorder}" Background="{TemplateBinding Background}"
      BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" >
            <Grid x:Name="ContentPanel" Margin="{TemplateBinding Padding}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ContentPresenter x:Name="Icon" Style="{StaticResource ContentPresenterType}"
                          ContentSource="Icon" Height="{DynamicResource {x:Static oui:Sizes.LargeHeightKey}}"
                          Width="{DynamicResource {x:Static oui:Sizes.LargeWidthKey}}"/>
                <Border x:Name="CheckMark" Margin="2" Visibility="Collapsed" VerticalAlignment="Center" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="8" Height="8" />
                <ContentPresenter x:Name="HeaderHost" RecognizesAccessKey="True" 
                          ContentSource="Header"
                          VerticalAlignment="Bottom" HorizontalAlignment="Center"
                          Grid.Row="1">
                    <ContentPresenter.Resources>
                        <ResourceDictionary>
                            <ResourceDictionary.MergedDictionaries>
                                <ouit:StringResources/>
                            </ResourceDictionary.MergedDictionaries>
                        </ResourceDictionary>
                    </ContentPresenter.Resources>
                </ContentPresenter>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="Header" Value="">
                <Setter TargetName="HeaderHost" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuDownBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Large">
                <Setter Property="oui:RibbonElement.TextWrapping" Value="Wrap"/>
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Medium">
                <Setter Property="Grid.Row" Value="0" TargetName="HeaderHost"/>
                <Setter Property="Grid.Column" Value="1" TargetName="HeaderHost"/>
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="HeaderHost"/>
                <Setter Property="Width" Value="{DynamicResource {x:Static oui:Sizes.MediumWidthKey}}" TargetName="Icon"/>
                <Setter Property="Height" Value="{DynamicResource {x:Static oui:Sizes.MediumHeightKey}}" TargetName="Icon"/>
                <Setter Property="oui:RibbonElement.MaxTextWidth" Value="100000"/>
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Small">
                <Setter Property="Grid.Row" Value="0" TargetName="HeaderHost"/>
                <Setter Property="Grid.Column" Value="1" TargetName="HeaderHost"/>
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="HeaderHost"/>
                <Setter Property="Width" Value="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" TargetName="Icon"/>
                <Setter Property="Height" Value="{DynamicResource {x:Static oui:Sizes.SmallHeightKey}}" TargetName="Icon"/>
                <Setter Property="oui:RibbonElement.MaxTextWidth" Value="100000"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="{x:Static oui:UIComponents.MenuButtonTemplateKey}" TargetType="{x:Type Button}">
        <Grid>
            <Rectangle x:Name="bg2" Fill="{TemplateBinding Background}"/>
            <ContentPresenter x:Name="content" RecognizesAccessKey="True"  />
        </Grid>
    </ControlTemplate>



    <ControlTemplate x:Key="{x:Static oui:UIComponents.TopLevelHeaderMenuItemLargeTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="ClassicBorder" Style="{StaticResource roundMenuItemBorder}"  Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid x:Name="ContentPanel">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border Name="buttonBorder" BorderBrush="#FFBDB489">
                    <Button Template="{StaticResource {x:Static oui:UIComponents.MenuButtonTemplateKey}}" Command="{TemplateBinding Command}"
                  CommandParameter="{TemplateBinding CommandParameter}"  Background="Transparent" Padding="1"
                  DockPanel.Dock="Top" Margin="0" VerticalAlignment="Top"  HorizontalAlignment="Center" x:Name="Button" Width="{DynamicResource {x:Static oui:Sizes.LargeWidthKey}}" Height="{DynamicResource {x:Static oui:Sizes.LargeHeightKey}}">
                        <ContentPresenter x:Name="Icon" ContentSource="Icon" Style="{StaticResource ContentPresenterType}"/>
                    </Button>
                </Border>
                <Border Name="arrowBorder"  Grid.Row="1">
                    <StackPanel x:Name="arrowPanel" TextElement.Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}">
                        <ContentPresenter Grid.Row="1" x:Name="HeaderHost" RecognizesAccessKey="True"  HorizontalAlignment="Center" ContentSource="Header" Margin="{TemplateBinding Padding}" />
                        <Path Grid.Row="2" VerticalAlignment="Center"  Margin="1 0 1 2" Data="{StaticResource downArrowGeometry}" Fill ="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}" HorizontalAlignment="Center"/>
                        <Rectangle Style="{StaticResource DebugRect}" Fill="DarkGreen"/>
                    </StackPanel>
                </Border>
                <Border Grid.Row="1" x:Name="CheckMark" Margin="2" Visibility="Collapsed" VerticalAlignment="Bottom" 
                Background="{TemplateBinding Foreground}" CornerRadius="1" Width="6" Height="6" />
                <Rectangle Style="{StaticResource DebugRect}" Fill="Cyan"/>
                <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="arrowPanel">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHoverBackgroundKey}}" TargetName="arrowPanel"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHover2BackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="Button">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" TargetName="Button"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHover2BackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True" SourceName="Button">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuPressedBackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowPressedBackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


    <ControlTemplate x:Key="{x:Static oui:UIComponents.TopLevelHeaderMenuItemMediumTemplateKey}" TargetType="{x:Type MenuItem}">
        <Border x:Name="ClassicBorder" Style="{StaticResource roundMenuItemBorder}"  Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid x:Name="ContentPanel">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Border Name="buttonBorder" BorderBrush="#FFBDB489">
                    <Button 
                        Template="{StaticResource {x:Static oui:UIComponents.MenuButtonTemplateKey}}" Command="{TemplateBinding Command}"
                        CommandParameter="{TemplateBinding CommandParameter}"  Background="Transparent" Padding="1"
                        Margin="0" VerticalAlignment="Top"  HorizontalAlignment="Center" x:Name="Button">
                        <StackPanel Orientation ="Horizontal" TextElement.Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}">
                            <ContentPresenter x:Name="Icon" ContentSource="Icon" Style="{StaticResource ContentPresenterType}" 
                                Width="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" Height="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}"/>
                            <ContentPresenter x:Name="HeaderHost" RecognizesAccessKey="True"  HorizontalAlignment="Center"
                                ContentSource="Header" Margin="{TemplateBinding Padding}" />
                        </StackPanel>
                    </Button>
                </Border>
                <Border Name="arrowBorder"  Grid.Column="1" Width="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" >
                    <Grid x:Name="arrowPanel" >
                        <Path VerticalAlignment="Center"  Margin="1 0 1 2" Data="{StaticResource downArrowGeometry}"  Fill ="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"
                  HorizontalAlignment="Center"/>
                    </Grid>
                </Border>
                <!--<Border Grid.Row="1" x:Name="CheckMark" Margin="2" Visibility="Collapsed" VerticalAlignment="Bottom" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="6" Height="6" /> -->
                <Rectangle Style="{StaticResource DebugRect}" Fill="Tomato"/>
                <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="arrowPanel">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHoverBackgroundKey}}" TargetName="arrowPanel"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHover2BackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="Button">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" TargetName="Button"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHover2BackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True" SourceName="Button">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuPressedBackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowPressedBackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <!--<Trigger Property="IsChecked" Value="true">
        <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
      </Trigger> -->
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="{x:Static oui:UIComponents.TopLevelHeaderMenuItemSmallTemplateKey}" TargetType="{x:Type MenuItem}">
            <Border x:Name="ClassicBorder" Style="{StaticResource roundMenuItemBorder}" 
                Background="{TemplateBinding Background}"  BorderThickness="{TemplateBinding BorderThickness}" 
                BorderBrush="{TemplateBinding BorderBrush}">
                <Grid x:Name="ContentPanel">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Border Name="buttonBorder" BorderBrush="#FFBDB489">
                        <Button Template="{StaticResource {x:Static oui:UIComponents.MenuButtonTemplateKey}}" Command="{TemplateBinding Command}"
                  CommandParameter="{TemplateBinding CommandParameter}"  Background="Transparent" Padding="1"
                  Margin="0" VerticalAlignment="Top"  HorizontalAlignment="Center" x:Name="Button" >
                            <StackPanel Orientation ="Horizontal" TextElement.Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}">
                                <ContentPresenter x:Name="Icon" ContentSource="Icon" Style="{StaticResource ContentPresenterType}"
                                Width="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" Height="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}"/>
                                <ContentPresenter x:Name="HeaderHost" RecognizesAccessKey="True"  HorizontalAlignment="Center"
                                ContentSource="Header" Margin="{TemplateBinding Padding}"/>
                            </StackPanel>
                        </Button>
                    </Border>
                    <Border Name="arrowBorder"  Grid.Column="1" Width="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" >
                        <Grid x:Name="arrowPanel" >
                            <Path VerticalAlignment="Center"  Margin="1 0 1 2" Data="{StaticResource downArrowGeometry}" Fill ="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}"
                  HorizontalAlignment="Center"/>
                        </Grid>
                    </Border>
                    <!--<Border Grid.Row="1" x:Name="CheckMark" Margin="2" Visibility="Collapsed" VerticalAlignment="Bottom" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="6" Height="6" /> -->
                    <Rectangle Style="{StaticResource DebugRect}" Fill="DarkBlue"/>
                    <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                        <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                            <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                        </Border>
                    </Popup>
                </Grid>
            </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="arrowPanel">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHoverBackgroundKey}}" TargetName="arrowPanel"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHover2BackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="Button">
                <Setter Property="Margin" Value="-1" TargetName="arrowPanel"/>
                <Setter Property="Margin" Value="-1" TargetName="Button"/>
                <Setter Property="BorderThickness" Value="1" TargetName="arrowBorder"/>
                <Setter Property="BorderThickness" Value="1" TargetName="buttonBorder"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" TargetName="Button"/>
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowHover2BackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True" SourceName="Button">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuPressedBackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuArrowPressedBackgroundKey}}" TargetName="arrowPanel"/>
            </Trigger>
            <!--<Trigger Property="IsChecked" Value="true">
        <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
        <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
      </Trigger> -->
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Small">
                <Setter TargetName="HeaderHost" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="oui:RibbonElement.ControlState" Value="Small" ></Condition>
                    <Condition Property="Icon" Value="{x:Null}" ></Condition>
                </MultiTrigger.Conditions>
                <Setter TargetName="HeaderHost" Property="Visibility" Value="Visible"/>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="MenuButtonKey" TargetType="{x:Type Button}">
        <Grid Loaded="FrameworkElement_OnLoaded">
            <Rectangle x:Name="bg" Fill="{TemplateBinding Background}"/>
            <ContentPresenter x:Name="content" />
        </Grid>
    </ControlTemplate>


    <ControlTemplate x:Key="TopLevelHeaderSmallTemplateKeyobsolete" TargetType="{x:Type MenuItem}">
        <Border x:Name="ClassicBorder" Style="{StaticResource roundBorder}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <DockPanel x:Name="ContentPanel" >
                <Button Template="{StaticResource MenuButtonKey}" Command="{TemplateBinding Command}"
                CommandParameter="{TemplateBinding CommandParameter}" DockPanel.Dock="Left" Margin="2"  Background="Transparent"
                VerticalAlignment="Stretch"  HorizontalAlignment="Left" x:Name="Button">
                    <ContentPresenter x:Name="Icon" ContentSource="Icon" Style="{StaticResource ContentPresenterType}"/>
                </Button>
                <StackPanel DockPanel.Dock="Right" x:Name="panel" Orientation="Horizontal">
                    <ContentPresenter x:Name="HeaderHost" RecognizesAccessKey="True" ContentSource="Header" Margin="{TemplateBinding Padding}" />
                    <Path Data="{StaticResource downArrowGeometry}" Fill ="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </StackPanel>
                <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </DockPanel>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Button" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="panel">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" TargetName="panel"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True" SourceName="Button">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" TargetName="Button"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <!--<Setter TargetName="CheckMark" Property="Visibility" Value="Visible" /> -->
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="Button" Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuDownBackgroundKey}}"/>
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="TopLevelHeaderSmallTemplateKeyNoCommand" TargetType="{x:Type MenuItem}">
        <Border x:Name="ClassicBorder" Style="{StaticResource roundBorder}" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <DockPanel x:Name="ContentPanel" Margin="1">
                <Internals:HeaderPresenterControl Header="{TemplateBinding Header}" Icon="{TemplateBinding Icon}" IsChecked="{TemplateBinding IsChecked}"></Internals:HeaderPresenterControl>
                <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </DockPanel>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


    <ControlTemplate x:Key="SubmenuHeaderTemplateKey" TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid Margin="{TemplateBinding Padding}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="12" Width="*"/>
                    <!--<ColumnDefinition Width="*" /> -->
                    <ColumnDefinition Width="Auto" SharedSizeGroup="InputGestureTextGroup" />
                    <ColumnDefinition Width="12" />
                </Grid.ColumnDefinitions>


                <Rectangle Width="1" Margin="0 -2 0 -2" Fill="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" VerticalAlignment="Stretch" HorizontalAlignment="Left" Visibility="Hidden" x:Name="sep" Grid.Column ="1"/>
                <ContentPresenter x:Name="Header2"  Visibility="Collapsed" Grid.Column="1" Margin="2" VerticalAlignment="Center" ContentSource="Header" />
                <Path x:Name="Arrow" Grid.Column="2" Margin="2" VerticalAlignment="Center"
                      Fill="{TemplateBinding Foreground}" Data="{StaticResource rightArrowGeometry}" />
                <Button Grid.Column="0" Margin="0" x:Name="Button" Command="{TemplateBinding Command}" 
                        CommandParameter="{TemplateBinding CommandParameter}"  Background="Transparent"
                Template="{StaticResource MenuButtonKey}" PreviewMouseLeftButtonUp="MenuItemPreviousMouseLeftButtonUp">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="12" Width="Auto" SharedSizeGroup="IconGroup" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <ContentPresenter Style="{StaticResource ContentPresenterType}" x:Name="Icon" Grid.Column="0" Margin="2" MaxHeight="32"  ContentSource="Icon" HorizontalAlignment="Left"/>
                        <Border x:Name="CheckMark" Grid.Column="0" Margin="2" VerticalAlignment="Center" Visibility="Collapsed" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="8" Height="8" />
                        <ContentPresenter x:Name="Header" RecognizesAccessKey="True" Grid.Column="1" Margin="2" VerticalAlignment="Center" ContentSource="Header" TextElement.Foreground="{DynamicResource {x:Static oui:OfficeBrushes.TextForegroundKey}}" />
                        <Rectangle Style="{StaticResource DebugRect}" Fill="Orange"/>
                    </Grid>

                </Button>
                <Popup x:Name="SubMenuPopup" Placement="Right" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="Command" Value="{x:Null}">
                <Setter TargetName="Button" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="False" SourceName="Button"/>
                    <Condition Property="IsHighlighted" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="Button" Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHighlightedHoverBackgroundKey}}" />
            </MultiTrigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="Visibility" Value="Visible" TargetName="sep"/>
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="SubmenuHeaderNoCommandTemplateKey" TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid Margin="{TemplateBinding Padding}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="20" Width="Auto"/>
                    <!--<ColumnDefinition Width="*" /> -->
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="12" />
                </Grid.ColumnDefinitions>
                <Rectangle Width="1" Margin="0 -2 0 -2" Fill="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" VerticalAlignment="Stretch" HorizontalAlignment="Left" Visibility="Hidden" x:Name="sep" Grid.Column ="1"/>
                <ContentPresenter
          Style="{StaticResource ContentPresenterType}" x:Name="Icon" Grid.Column="0" Margin="2" ContentSource="Icon"
          MaxWidth="{DynamicResource {x:Static oui:Sizes.LargeWidthKey}}" MaxHeight="{DynamicResource {x:Static oui:Sizes.LargeHeightKey}}"/>

                <ContentPresenter x:Name="Header"  Visibility="Visible" Grid.Column="1" Margin="2" VerticalAlignment="Center" ContentSource="Header" />
                <Border x:Name="CheckMark" Grid.Column="0" Margin="2" VerticalAlignment="Center" Visibility="Collapsed" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="8" Height="8" />
                <Path x:Name="Arrow" Grid.Column="2" Margin="2" VerticalAlignment="Center" Fill="{TemplateBinding Foreground}" 
                      Data="{StaticResource rightArrowGeometry}" />
                <Rectangle Style="{StaticResource DebugRect}" Fill="DarkRed"/>

                <Popup x:Name="SubMenuPopup" Placement="Right" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                    </Border>
                </Popup>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <!-- <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsMouseOver" Value="False" SourceName="Button"/
          <Condition Property="IsHighlighted" Value="True"/>
        </MultiTrigger.Conditions>
        <Setter TargetName="Button" Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.HighlightedMenuHoverBackgroundKey}}" />
      </MultiTrigger> -->
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="Visibility" Value="Visible" TargetName="sep"/>
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="TopLevelHeaderTemplateKeyNoCommand" TargetType="{x:Type MenuItem}">
        <Border x:Name="ClassicBorder" Style="{StaticResource roundBorder}"  Background="{TemplateBinding Background}" 
            BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid>
                <Internals:HeaderPresenterControl Tag="2" x:Name="headerPresenter"
                                                  Icon="{TemplateBinding Icon}" Header="{TemplateBinding Header}" IsChecked="{TemplateBinding IsChecked}" ></Internals:HeaderPresenterControl>
                <Rectangle Fill="MistyRose" Style="{StaticResource DebugRect}"></Rectangle>
                <Popup x:Name="SubMenuPopup" VerticalOffset="1" HorizontalOffset="-2"   Placement="Bottom" IsOpen="{Binding Path=IsSubmenuOpen,RelativeSource={RelativeSource TemplatedParent}}" Focusable="false" >
                    <Border Background="White" BorderBrush="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" BorderThickness="1">
                        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden" MaxHeight="500">
                        <ItemsPresenter Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" />
                        </ScrollViewer>
                    </Border>
                </Popup>

            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
            <Trigger Property="IsOpen" Value="True" SourceName="SubMenuPopup">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuDownBackgroundKey}}" />
                <Setter Property="IsOpen" Value="True" TargetName="headerPresenter"  />
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Medium">
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="ClassicBorder"/>
                <Setter Property="Padding" Value="1"/>
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Small">
                <Setter Property="HorizontalAlignment" Value="Left" TargetName="ClassicBorder"/>
                <Setter Property="Padding" Value="1"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="SubmenuItemTemplateKey" TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid Margin="{TemplateBinding Padding}" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="12" Width="Auto" SharedSizeGroup="IconGroup" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" SharedSizeGroup="InputGestureTextGroup" />
                    <ColumnDefinition Width="12" />
                </Grid.ColumnDefinitions>
                <ContentPresenter
          Style="{StaticResource ContentPresenterType}" x:Name="Icon" Grid.Column="0" Margin="2" ContentSource="Icon"
          MaxWidth="{DynamicResource {x:Static oui:Sizes.LargeWidthKey}}" MaxHeight="{DynamicResource {x:Static oui:Sizes.LargeHeightKey}}"/>
                <Border x:Name="CheckMark" Grid.Column="0" Margin="2" VerticalAlignment="Center" Visibility="Collapsed" Background="{TemplateBinding Foreground}" CornerRadius="1" Width="6" Height="6" />
                <ContentPresenter x:Name="Header" RecognizesAccessKey="True" Grid.Column="1" Margin="2" VerticalAlignment="Center" ContentSource="Header" />
                <Rectangle Style="{StaticResource DebugRect}" Fill="Red"/>

                <!--<TextBlock x:Name="InputGestureText" Grid.Column="2" Margin="2" VerticalAlignment="Center" Text="{TemplateBinding InputGestureText}" /> -->
                <!--<CheckBox Content="cc" IsChecked="{TemplateBinding IsHighlighted}"/> -->
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="oui:RibbonElement.IsIconVisible" Value="False">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed"/>
            </Trigger>
            <Trigger Property="Icon" Value="{x:Null}">
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CheckMark" Property="Visibility" Value="Visible" />
                <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
            <!--
      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
        <Setter Property="BorderBrush" Value="Silver" />
      </Trigger>
      -->
            <Trigger Property="oui:RibbonElement.ControlState" Value="Small">
                <Setter Property="MaxWidth" Value="{DynamicResource {x:Static oui:Sizes.SmallWidthKey}}" TargetName="Icon"/>
                <Setter Property="MaxHeight" Value="{DynamicResource {x:Static oui:Sizes.SmallHeightKey}}"  TargetName="Icon"/>
            </Trigger>
            <Trigger Property="oui:RibbonElement.ControlState" Value="Medium">
                <Setter Property="MaxWidth" Value="{DynamicResource {x:Static oui:Sizes.MediumWidthKey}}"  TargetName="Icon"/>
                <Setter Property="MaxHeight" Value="{DynamicResource {x:Static oui:Sizes.MediumHeightKey}}"  TargetName="Icon"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <ControlTemplate x:Key="{x:Static oui:ComponentKeys.SubmenuItemNoPaddingTemplateKey}"
                   TargetType="{x:Type MenuItem}">
        <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
            <Grid Margin="{TemplateBinding Padding}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ContentPresenter x:Name="Header" Grid.Column="0" Margin="2" VerticalAlignment="Center" ContentSource="Header" />
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsHighlighted" Value="True">
                <Setter Property="Background" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBackgroundKey}}" />
                <Setter Property="BorderBrush" Value="{DynamicResource {x:Static oui:OfficeBrushes.MenuHoverBorderBrushKey}}" />
                <Setter Property="oui:HighlightElement.IsHighlighted" Value="True" />

            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


</ResourceDictionary>